#!/usr/bin/python
# -*- coding:UTF-8 -*-
# @Time    : 2019/1/10 10:54
# @Author  : 王志鹏
# @Site    : 
# @File    : d1.py
# @Software: PyCharm

"""
访问者模式
"""
import abc


class Person(object):
    __metaclass__ = abc.ABCMeta

    # def __init__(self):
    #     self.action = None
    #
    # def getAction(self):
    #     return self.action
    #
    # def setAction(self, action):
    #     self.action = action

    @abc.abstractmethod
    def Accept(self, visitor):
        pass


class Man(Person):
    def Accept(self, visitor):
        visitor.getManConclision(self)


class Woman(Person):
    def Accept(self, visitor):
        visitor.getWomanConclision(self)


class Action(object):
    __metaclass__ = abc.ABCMeta

    @abc.abstractmethod
    def getManConclision(self, person): pass

    @abc.abstractmethod
    def getWomanConclision(self, person): pass


class Success(Action):
    type = "成功"

    def getManConclision(self, person):
        print "%s %s 时,背后多半有一个伟大的女人!" % (person.__class__.__name__, self.type)

    def getWomanConclision(self, person):
        print "%s %s 时,背后多半有一个不成功的男人!" % (person.__class__.__name__, self.type)


class Failing(Action):
    type = "失败"

    def getManConclision(self, person):
        print "%s %s 时,闷头喝酒谁也不用劝!" % (person.__class__.__name__, self.type)

    def getWomanConclision(self, person):
        print "%s %s 时,眼泪汪汪谁也劝不了!" % (person.__class__.__name__, self.type)


class Amativeness(Action):
    type = "恋爱"

    def getManConclision(self, person):
        print "%s %s 时,凡事不懂也要装懂" % (person.__class__.__name__, self.type)

    def getWomanConclision(self, person):
        print "%s %s 时,遇事懂也装作不懂!" % (person.__class__.__name__, self.type)


class Marriage(Action):
    type = "婚姻"

    def getManConclision(self, person):
        print "%s %s 时,凡事不懂也要装懂" % (person.__class__.__name__, self.type)

    def getWomanConclision(self, person):
        print "%s %s 时,遇事懂也装作不懂!" % (person.__class__.__name__, self.type)


class ObjectStructure(object):
    def __init__(self):
        self.list = []

    def addAttach(self, persion):
        self.list.append(persion)

    def delDetach(self, persion):
        self.list.remove(persion)

    def disPlay(self, action):
        for i, v in enumerate(self.list):
            v.Accept(action)


if __name__ == '__main__':
    o = ObjectStructure()
    o.addAttach(Man())
    o.addAttach(Woman())

    v1 = Success()
    o.disPlay(v1)
    v2 = Failing()
    o.disPlay(v2)
    v3 = Amativeness()
    o.disPlay(v3)
    v4 = Marriage()
    o.disPlay(v4)
